//
//  HYNavigationController.m
//  (Normal)
//
//  Created by Ezra on 16/5/29.
//  Copyright © 2016年 Ezra. All rights reserved.
//

#import "HYNavigationController.h"

@interface HYNavigationController ()<UIGestureRecognizerDelegate>

@end

@implementation HYNavigationController

+(void)load
{
    //这个self怎么拿到的
    UINavigationBar *navBar = [UINavigationBar appearanceWhenContainedIn:self, nil];
    
    NSMutableDictionary *attr = [NSMutableDictionary dictionary];
    attr[NSFontAttributeName] = [UIFont systemFontOfSize:20];
    navBar.titleTextAttributes = attr;
    
    [navBar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackgroundWhite"] forBarMetrics:UIBarMetricsDefault];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //打印这句可以得到target 和 action
//    NSLog(@"%@",self.interactivePopGestureRecognizer);
    
    id target = self.interactivePopGestureRecognizer.delegate;
    
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:target action:@selector(handleNavigationTransition:)];
    
    [self.view addGestureRecognizer:pan];
    
    self.interactivePopGestureRecognizer.enabled = NO;
    
    pan.delegate = self;
    
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    
    if (self.childViewControllers.count > 0 ) {
        
        UIBarButtonItem *item = [UIBarButtonItem itemWithTitle:@"返回" titleColor:[UIColor blackColor] titleHighColor:[UIColor redColor] image:[UIImage imageNamed:@"navigationButtonReturn"] selImage:[UIImage imageNamed:@"navigationButtonReturnClick"]  addTarget:self action:@selector(back)];
        
         //注意是viewController 不是self
        viewController.navigationItem.leftBarButtonItem = item;
        
        //隐藏底部tabbar
        viewController.hidesBottomBarWhenPushed = YES;
        
    }
    
    [super pushViewController:viewController animated:animated];
    
}
- (void)back
{
    [self popViewControllerAnimated:YES];
}

#pragma 手势滑动代理方法
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
     return self.childViewControllers.count > 1;
}


@end
